package com.hospital.billcommon.module.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hospital.billcommon.module.entity.InpBillItem;
import com.hospital.billcommon.module.mapper.InpPriceMapper;
import com.hospital.billcommon.module.service.InpPriceService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description 住院患者数据插入实现类
 * @author: liuwei
 * @create 2020/5/21 5:11 下午
 **/
@Service
@Transactional(rollbackFor = Exception.class)
public class InpPriceServiceImpl extends ServiceImpl<InpPriceMapper, InpBillItem> implements InpPriceService {

    @Resource
    private InpPriceMapper inpPriceMapper;
    @Override
    public boolean insertInpBillItemList(List<InpBillItem> list) {
        for (InpBillItem item:list){
            try {
                int res = inpPriceMapper.insert(item);
                if (res <= 0) {
                    throw new RuntimeException("数据插入失败");
                }
            }catch (Exception e){
                if (e.getMessage().contains("ORA-20001")){
                    throw new RuntimeException("插入费用数据异常,材料库存不足或基础数据异常" + e.getMessage());
                }
                throw new RuntimeException("插入费用数据异常" + e.getMessage());
            }
        }
        return true;
    }

    @Override
    public String getItemRcptClass(String itemCode, String itemSpec) {
        return inpPriceMapper.getItemRcptClass(itemCode, itemSpec);
    }
}
